package permission

import (
	"github.com/goravel/framework/contracts/http"

	"goravel/app/services"
)

type MenuController struct {
	//Dependent services
	menuService services.MenuService
}

func NewMenuController() *MenuController {
	return &MenuController{
		//Inject services
		menuService: services.MenuService{},
	}
}

func (r *MenuController) GetMenus(ctx http.Context) http.Response {
	adminId := ctx.Value("adminId").(int)
	menus, err := r.menuService.MenuWithRole(ctx, adminId)
	if err != nil {
		return ctx.Response().Success().Json(http.Json{
			"code": http.StatusInternalServerError,
			"msg":  err.Error(),
		})
	}
	return ctx.Response().Success().Json(http.Json{
		"code":    http.StatusOK,
		"data":    menus,
		"message": "success",
	})
}
